home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C++
/
Applications
/
Mic-1 v1.0
/
Project and Source
/
Source
/
mic_main.cpp
< prev
next >
Wrap
Text File
|
1996-05-11
|
4KB
|
159 lines
/*
"main.cpp"
Here is the main code. Maybe later (if I have the time) I will turn this
into a real Mic-1 simulator with a mac interface.
*/
#include <iostream.h>
#include <fstream.h>
#include "mic_main.h"
#include "mic_global_functions.h"
#include "mic_dump.h"
#include "mic_clock.h"
#include "mic_memory.h"
#include "mic_data_path.h"
#include "mic_control.h"
// cycleBreakPoint
const short kRunConstant = 0;
const short kRunInterrupted = 1;
DataRec Data;
OptionsRec options;
// Local prototypes
void InitGlobalDataRec (void);
void mainMicScreen (void);
void doAbout (void);
void doGo (Mic_1_Class& Mic, short cycleBreakPoint);
void doOptions (Mic_1_Class& Mic);
void main (void)
{
char c = 'r';
short error = 0;
long tickStart, ticks;
while ((c == 'r') || (c == 'R')) // if char is 'r' or 'R', they want to reset it.
{
Mic_1_Class Mic;
// we have a separate init procs (instead of a constructor) to add error checking
error = InitMicMemory(Mic);
error = InitMicControl(Mic);
InitGlobalDataRec();
cout << "Welcome to a cool Mic-1 simulator" << endl;
cout << " by John DeWeese in April 1996" << endl;
mainMicScreen();
if (error)
Death(error);
while (!Data.Done)
{
cout << ">> ";
cin >> c;
switch (c)
{
case '?': doAbout(); break; // ? = about box
case 'd': case 'D': doDump(Mic); mainMicScreen(); break; // d = dump something
case 'o': case 'O': doOptions(Mic); mainMicScreen(); break; // o = options
case 'c': case 'C': doGo(Mic, kRunInterrupted); mainMicScreen(); break; // c = cycle once
case 'g': case 'G': doGo(Mic, kRunConstant); mainMicScreen(); break; // g = GO!
case 'r': case 'R': // r = reset
case 'x': case 'X': case 'q': case 'Q': Data.Done = true; break; // x = exit
default: cout << "huh?" << endl; break;
}
}
if ((c == 'q') || (c == 'Q'))
{
cout << endl << "Dumping to the final file...";
Dump(Mic, kFromEverything, kToFinalFile);
cout << " done." << endl;
cout << endl;
}
}
cout << "<done>";
}
void InitGlobalDataRec (void)
{
Data.Done = false;
Data.doneExecuting = false;
Data.Cycle = 0;
Data.CPS = 0.0;
}
void mainMicScreen (void)
{
cout << " ___________" << endl;
cout << "___/ MAIN MENU \\____________________________" << endl;
cout << "| ? - About | d - Dump to a stream |" << endl;
cout << "| o - Options | c - Cycle once |" << endl;
cout << "| r - Reset | g - GO! (Continuous cycle) |" << endl;
cout << "|-------------+-----------------------------|" << endl;
cout << "| x - Exit | q - Quit (dump&exit) |" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout << " cycles = " << Data.Cycle << endl;
cout << "cycles/second = "; if (Data.CPS > 0) cout << Data.CPS; else cout << "-";
cout << endl << endl;
}
void doAbout (void)
{
InitCursor();
Alert(129, nil);
}
void doGo (Mic_1_Class& Mic, short cycleBreakPoint)
{
long startCycle = Data.Cycle, diffCycle = 1;
long ticks;
Boolean userBreak = false;
ticks = TickCount();
do
{
CYCLE(Mic); // do one full clock cycle
Data.Cycle++;
diffCycle++;
if (CheckForEscapeKey())
userBreak = true;
diffCycle = 1;
}
while ((cycleBreakPoint == kRunConstant) && (!Data.doneExecuting) && (!userBreak));
if ((ticks = TickCount() - ticks) > 0)
Data.CPS = 60*(Data.Cycle - startCycle)/(ticks);
else Data.CPS = 0.0;
}
void doOptions (Mic_1_Class& Mic)
{
Boolean done = false;
char c;
cout << endl;
cout << "__OPTIONS________________________________" << endl;
cout << "Set the options for running the Mic-1" << endl;
cout << " <none so far>" << endl;
cout << " x - escape back to the previos menu" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
while (!done)
{
cout << "options >> ";
cin >> c;
switch (c)
{
case 'x': case 'X': done = true; break;
default: cout << "huh?" << endl; break;
}
}
}